package com.lihao.demo1;

import android.app.Activity;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;


import com.lihao.demo1.view.PagerTabStrip;

import java.util.HashMap;
import java.util.Map;



/**
 * 主界面
 * Created by zengqiang on 2015/11/26.
 */

public class NewMainActivity extends FragmentActivity {
    private static final int HANDLER_BACK = 1;
    private final Map<Integer, Fragment> mFragments = new HashMap<>();

    ImageView mIvUserCenter;
    ImageView mIvSearch;
    PagerTabStrip mTabs;
    ViewPager mVpContent;
    //    @Bind(R.id.ll_title)
//    LinearLayout llTitle;
//    @Bind(R.id.all_root_view)
//    RelativeLayout allRootView;
    // 返回时是否退出客户端
    private boolean mIsBackExit = false;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case HANDLER_BACK: {
                    mIsBackExit = false;
                    break;
                }
            }
            super.handleMessage(msg);
        }
    };
    private MainPagerAdapter mPageAdapter;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_main);
//
//        mIvUserCenter.setEnabled(false);
//        mIvSearch.setEnabled(false);
//        mVpContent.setOffscreenPageLimit(2);
//        mPageAdapter = new MainPagerAdapter(getSupportFragmentManager());
//        int[] icons = {R.drawable.icon_tab_concert, R.drawable.icon_tab_activities, R.drawable.icon_tab_other};
//        mVpContent.setAdapter(mPageAdapter);
//        //mVpContent.setPageTransformer(true,new SimplePageTransform());
//
//        mTabs.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
//            @Override
//            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//
//            }
//
//            @Override
//            public void onPageSelected(int position) {
////                MobclickAgent.onEvent(NewMainActivity.this, "main", "" + position);
//            }
//
//            @Override
//            public void onPageScrollStateChanged(int state) {
//
//            }
//        });
////        AdvBeanInfo adInfo = getIntent().getParcelableExtra(AppIntentGlobalName.ADINFO);
////        if (adInfo != null) {
////            handlerIntent(adInfo, false);
////            Log.d("mainUI", "______________+++++++++++++:" + adInfo.toString());
////        }
//
//
//
////        TelephonyManager telManager = (TelephonyManager) getSystemService(Activity.TELEPHONY_SERVICE);
////        String operator = telManager.getSimOperator();
////        Log.d("NewMainActivity", "operator：" + operator);
////        if (operator != null) {
////            if (operator.equals("46000") || operator.equals("46002")) {
////                Log.d("NewMainActivity", "中国移动");
////                new Thread(new T1()).start();
////            } else if (operator.equals("46001")) {
////                Log.d("NewMainActivity", "中国联通");
////            } else if (operator.equals("46003")) {
////                Log.d("NewMainActivity", "中国电信");
////            }
////        }
//
    }





    @Override
    protected void onResume() {
        super.onResume();

    }

    public FragmentManager getSupportFragmentManager() {
        return super.getSupportFragmentManager();
    }

//    @OnClick(R.id.iv_left)
    public void titleLeftOnClick(View view) {
//        Intent userCenter = new Intent(this, NewUserCenterActivity.class);
//        startActivity(userCenter);
//        overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right);
    }




    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


    private class MainPagerAdapter extends FragmentStatePagerAdapter {
        private final String[] TITLES = {getString(R.string.concert), getString(R.string.concert_activities), getString(R.string.concert_scene)};

        public MainPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return TITLES[position];
        }

        @Override
        public Fragment getItem(int position) {
            Fragment f = mFragments.get(position);
            if (f != null) {
                return f;
            }
            switch (position) {
                case 0:
//                    f = new ConcertListFragment();
                    break;
                case 1:
//                    f = new ActionListFragment();
                    break;
                case 2:
//                    f = new OnLiveFragment();
                    break;
                default:
//                    f = new OnLiveFragment();
                    break;
            }
            mFragments.put(position, f);
            return f;
        }

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            mFragments.remove(position);
            super.destroyItem(container, position, object);
        }
    }
//    ///zq 测试
//    public class SimplePageTransform implements ViewPager.PageTransformer {
//
//        @Override
//        public void transformPage(View view, float position) {
//            int width = view.getWidth();
//            int pivotX = 0;
//            if (position <= 1 && position > 0) {// right scrolling
//                pivotX = 0;
//            } else if (position == 0) {
//
//            } else if (position < 0 && position >= -1) {// left scrolling
//                pivotX = width;
//            }
//            //设置x轴的锚点
//            view.setPivotX(pivotX);
//            //设置绕Y轴旋转的角度
//            view.setRotationY(60f * position);
//        }
//    }
}
